//
//  MVPlayerViewController.m
//  wind
//
//  Created by dllo on 16/1/13.
//  Copyright © 2016年 李金明. All rights reserved.
//

#import "MVPlayerViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "DetailMVTableViewCell.h"
#import "SuggestedMVTableViewCell.h"
#import "LJMNetworkTool.h"
#import "LJMRankSubRoot_MVModel.h"
#import "MVFullViewController.h"
#import "UMSocial.h"


@interface MVPlayerViewController ()<UITableViewDelegate, UITableViewDataSource, detailMVShareDelegate, UMSocialUIDelegate>

@property (nonatomic, retain) AVPlayer *player;// 播放器对象
@property (nonatomic, retain) UIView *MvPlayView;// 播放器容器
@property (nonatomic, retain) UIButton *playBtn;// 播放/暂停按钮
@property (nonatomic, retain) UISlider *slider;// 播放进度
@property (nonatomic, retain) UIButton *largeBtn;// 全屏按钮
@property (nonatomic, retain) UITableView *tableV;//下面的tableView
@property (nonatomic, retain) UIView *tempV;// 放播放/暂停按钮的view
@property (nonatomic, retain) UILabel *currentL;// 当前时间
@property (nonatomic, retain) UILabel *totalL;// 总时长
@property (nonatomic, retain) UIButton *tempBtn;// mv中间的开始按钮
@property (nonatomic, retain) UIProgressView *progress;// 缓冲进度条
@property (nonatomic, retain) NSMutableArray *suggestedArr;// 推荐mv数组
@property (nonatomic, assign) BOOL isRotation;// 全屏标识
@property (nonatomic, assign) CGRect originalFrame;//记录播放器原始frame
@property (nonatomic, retain) AVPlayerItem *playerItem; // avplayeritem
@property (nonatomic, retain) UISlider *volumeSlider; // 音量slider

@end

@implementation MVPlayerViewController

- (void)setMyID:(NSNumber *)myID
{
    if (_myID != myID) {
        [_myID release];
        _myID = [myID retain];
    }
    [self.tableV reloadData];
}

- (void)setMvStr:(NSString *)mvStr
{
    if (_mvStr != mvStr) {
        [_mvStr release];
        _mvStr = [mvStr retain];
    }
    [self.tableV reloadData];
}

- (void)dealloc
{
    [_player release];
    [_MvPlayView release];
    [_playBtn release];
    [_slider release];
    [_largeBtn release];
    [_mvStr release];
    [_tableV release];
    [_myID release];
    [_tempV release];
    [_currentL release];
    [_totalL release];
    [_tempBtn release];
    [_videoName release];
    [_singerName release];
    [_progress release];
    [_suggestedArr release];
    [_playerItem release];
    [_volumeSlider release];
    [self removeObserverFromPlayerItem:self.player.currentItem];
    [self removeNotification];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.originalFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 3);
    
    self.isRotation = NO;
    
    [self createSubviews:self.originalFrame];
    
    [self getData];
    
    [self.player play];
    
}

- (void)getData
{
//    http://api.dongting.com/sim/mv/2001534/similarity
//    NSLog(@"%@", self.myID);
    NSString *mid = [self.myID stringValue];
    NSString *urlStr = [NSString stringWithFormat:@"http://api.dongting.com/sim/mv/%@/similarity", mid];
//    NSLog(@"%@", urlStr);
    [LJMNetworkTool getNetWithURL:urlStr body:nil headFile:nil responseStyle:LJMResponseJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        self.suggestedArr = [NSMutableArray array];
        
        NSMutableArray *arr = [responseObject objectForKey:@"data"];
        for (NSMutableDictionary *dic in arr) {
            LJMRankSubRoot_MVModel *model = [[LJMRankSubRoot_MVModel alloc] init];
            model.singerName = [dic objectForKey:@"singerName"];
            model.videoName = [dic objectForKey:@"videoName"];
            model.MVListArr = [dic objectForKey:@"mvList"];
            model.pickCount = [[dic objectForKey:@"pickCount"] stringValue];
            model.bulletCount = [[dic objectForKey:@"bulletCount"] stringValue];
            NSMutableDictionary *tempDic = [[dic objectForKey:@"mvList"] firstObject];
            model.myId = [tempDic objectForKey:@"videoId"];
            model.picUrl = [tempDic objectForKey:@"picUrl"];
            [self.suggestedArr addObject:model];
            [model release];
        }
        [self.tableV reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
    }];

}

- (void)createSubviews:(CGRect)frame
{
    [self createMVView:frame];
    
    [self createTableView];
    
}
//视频播放view
- (void)createMVView:(CGRect)frame
{
    // 创建播放器容器
    self.MvPlayView = [[UIView alloc] initWithFrame:frame];
    self.MvPlayView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.MvPlayView];
    [_MvPlayView release];
    
    // 创建播放器层
    AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
    playerLayer.frame = frame;
    [self.MvPlayView.layer addSublayer:playerLayer];
    
    self.tempBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.tempBtn setImage:[UIImage imageNamed:@"iconfont-iconfontbofang"] forState:UIControlStateNormal];
    [self.tempBtn addTarget:self action:@selector(tempBtnAction) forControlEvents:UIControlEventTouchUpInside];
    self.tempBtn.hidden = YES;
    [self.MvPlayView addSubview:self.tempBtn];
    [self.tempBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.center.equalTo(self.MvPlayView);
        make.size.mas_equalTo(CGSizeMake(50, 50));
        
    }];
    
//    // 音量slider
//    self.volumeSlider = [[UISlider alloc] init];
//    self.volumeSlider.bounds = CGRectMake(0, 0, self.MvPlayView.frame.size.height, self.MvPlayView.frame.size.width / 2);
//    self.volumeSlider.center = CGPointMake(self.MvPlayView.frame.size.width / 4, self.MvPlayView.frame.size.height / 2);
//    self.volumeSlider.backgroundColor = [UIColor clearColor];
//    self.volumeSlider.minimumValue = 0;
//    self.volumeSlider.maximumValue = 10;
//    [self.volumeSlider setValue:5];
//    [self.volumeSlider addTarget:self action:@selector(volumeSet:) forControlEvents:UIControlEventValueChanged];
//    CGAffineTransform trans = CGAffineTransformMakeRotation(M_PI * -0.5);
//    self.volumeSlider.transform = trans;
//    [self.MvPlayView addSubview:self.volumeSlider];
//    [_volumeSlider release];

    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(10, 10, 40, 40);
    [backBtn setImage:[UIImage imageNamed:@"iconfont-back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.MvPlayView addSubview:backBtn];
    
    self.tempV = [[UIView alloc] initWithFrame:CGRectMake(0, self.MvPlayView.frame.size.height - 50, self.MvPlayView.frame.size.width, 50)];
    self.tempV.backgroundColor = [UIColor blackColor];
    self.tempV.alpha = 0.6;
    [self.MvPlayView addSubview:self.tempV];
    [_tempV release];
    
    self.playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playBtn.frame = CGRectMake(10, 10, 30, 30);
    [self.playBtn setImage:[UIImage imageNamed:@"iconfont-zanting"] forState:UIControlStateNormal];
    [self.playBtn addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.tempV addSubview:self.playBtn];
    
    self.largeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.largeBtn.frame = CGRectMake(self.MvPlayView.frame.size.width - 50, 10, 30, 30);
    [self.largeBtn setImage:[UIImage imageNamed:@"iconfont-quanping"] forState:UIControlStateNormal];
    [self.largeBtn addTarget:self action:@selector(largeAction) forControlEvents:UIControlEventTouchUpInside];
    [self.tempV addSubview:self.largeBtn];
    
    self.progress = [[UIProgressView alloc] initWithFrame:CGRectMake(52, 14, self.MvPlayView.frame.size.width - self.playBtn.frame.size.width - self.largeBtn.frame.size.width - 75, 10)];
    self.progress.progressTintColor = [UIColor lightGrayColor];
    self.progress.trackTintColor = [UIColor whiteColor];
    [self.tempV addSubview:self.progress];
    [_progress release];

    self.slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 10, self.MvPlayView.frame.size.width - self.playBtn.frame.size.width - self.largeBtn.frame.size.width - 60, 10)];
    self.slider.minimumTrackTintColor = [UIColor blueColor];
    self.slider.maximumTrackTintColor = [UIColor clearColor];
    [self.slider setThumbImage:[UIImage imageNamed:@"iconfont-yuandian"] forState:UIControlStateNormal];
    [self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    [self.tempV addSubview:self.slider];
    [_slider release];
    
    
    self.currentL = [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 50, 20)];
    self.currentL.text = @"00:00";
    self.currentL.textColor = [UIColor whiteColor];
    [self.tempV addSubview:self.currentL];
    [_currentL release];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 25, 5, 20)];
    label.text = @"/";
    label.textColor = [UIColor whiteColor];
    [self.tempV addSubview:label];
    [label release];
    
    self.totalL = [[UILabel alloc] initWithFrame:CGRectMake(105, 25, 50, 20)];
    self.totalL.textColor = [UIColor whiteColor];
    self.totalL.text = @"00:00";
    [self.tempV addSubview:self.totalL];
    [_totalL release];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.MvPlayView addGestureRecognizer:tap];
    

}


// tableview
- (void)createTableView
{
    self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, self.MvPlayView.frame.size.height, SCREEN_WIDTH, SCREEN_HEIGHT * 2 / 3) style:UITableViewStylePlain];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    [self.view addSubview:self.tableV];
    [_tableV release];
}

// 选中行事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        // 重新取数据
        LJMRankSubRoot_MVModel *model = [self.suggestedArr objectAtIndex:indexPath.row];
        self.mvStr = [[model.MVListArr firstObject] objectForKey:@"url"];
        NSLog(@"%@", self.mvStr);
        self.myID = model.myId;
        NSLog(@"%@", [self.myID stringValue]);
        self.videoName = model.videoName;
        self.singerName = model.singerName;
        [self getData];
        
        // 切换视频
        [self removeNotification];
        [self removeObserverFromPlayerItem:self.player.currentItem];
        AVPlayerItem *playerItem=[self getPlayItem:0];
        [self addObserverToPlayerItem:playerItem];
        //切换视频
        [self.player replaceCurrentItemWithPlayerItem:playerItem];
        [self addNotification];

    }
    
}

// 区标题
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (1 == section) {
        return @"推荐MV";
    } else {
        return nil;
    }
}

// 行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.section) {
        return SCREEN_HEIGHT / 4;
    } else {
        return SCREEN_HEIGHT / 4.5;
    }
}

// 区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

// 行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    } else {
        return self.suggestedArr.count;
    }
}

// cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.section) {
        static NSString *detailCell = @"detailCell";
        DetailMVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:detailCell];
        if (cell == nil) {
            cell = [[[DetailMVTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:detailCell] autorelease];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.videoName.text = self.videoName;
        cell.singerName.text = self.singerName;
        cell.delegate = self;
        return cell;
        
    } else {
        static NSString *suggestCell = @"suggestCell";
        SuggestedMVTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:suggestCell];
        if (cell == nil) {
            cell = [[[SuggestedMVTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:suggestCell] autorelease];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        LJMRankSubRoot_MVModel *model = [self.suggestedArr objectAtIndex:indexPath.row];
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:model.picUrl] placeholderImage:[UIImage imageNamed:@"clamdown"]];
        cell.songName.text = model.videoName;
        cell.singerName.text = model.singerName;
        cell.pickCount.text = model.pickCount;
        cell.bulletCount.text = model.bulletCount;
        
        return cell;
    }
}

// 视频上的后退按钮
- (void)backAction
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        [self stop];
    }];
}

/**
 *  初始化播放器
 *
 *  @return 播放器对象
 */
-(AVPlayer *)player{
    if (!_player) {
        self.playerItem=[self getPlayItem:0];
        _player=[AVPlayer playerWithPlayerItem:self.playerItem];
        
        
        [self addProgressObserver];
        
        [self addObserverToPlayerItem:self.playerItem];
    }
    return _player;
}

/**
 *  根据视频索引取得AVPlayerItem对象
 *
 *  @param videoIndex 视频顺序索引
 *
 *  @return AVPlayerItem对象
 */
-(AVPlayerItem *)getPlayItem:(int)videoIndex{

    NSURL *url=[NSURL URLWithString:self.mvStr];
    AVPlayerItem *playerItem=[AVPlayerItem playerItemWithURL:url];
    return playerItem;
}
#pragma mark - 通知
/**
 *  添加播放器通知
 */
-(void)addNotification{
    //给AVPlayerItem添加播放完成通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem];
}

-(void)removeNotification{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

/**
 *  播放完成通知
 *
 *  @param notification 通知对象
 */
-(void)playbackFinished:(NSNotification *)notification{
    NSLog(@"视频播放完成.");
}

#pragma mark - 监控
/**
 *  给播放器添加进度更新
 */
-(void)addProgressObserver{
//    AVPlayerItem *playerItem=self.player.currentItem;
    //这里设置每秒执行一次
    [self.player addPeriodicTimeObserverForInterval:CMTimeMake(1.0, 10.0) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) {
        float current=CMTimeGetSeconds(time);
//        float total=CMTimeGetSeconds([playerItem duration]);
        if (current) {
//            NSLog(@"%f", current);
            [self.slider setValue:current animated:YES];
            int currentTime = (int)current;
            int m = currentTime / 60;
            int s = currentTime % 60;
            NSString *strM =nil;
            NSString *strS =nil;
            if (m < 10) {
                strM = [NSString stringWithFormat:@"0%d",m];
            } else {
                strM = [NSString stringWithFormat:@"%d", m];
            }
            
            if (s < 10) {
                strS = [NSString stringWithFormat:@"0%d", s];
            } else {
                strS = [NSString stringWithFormat:@"%d", s];
            }
            self.currentL.text = [NSString stringWithFormat:@"%@:%@",strM, strS];
        }
    }];
}

/**
 *  给AVPlayerItem添加监控
 *
 *  @param playerItem AVPlayerItem对象
 */
-(void)addObserverToPlayerItem:(AVPlayerItem *)playerItem{
    //监控状态属性，注意AVPlayer也有一个status属性，通过监控它的status也可以获得播放状态
    [playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    //监控网络加载情况属性
    [playerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];
}
-(void)removeObserverFromPlayerItem:(AVPlayerItem *)playerItem{
    [playerItem removeObserver:self forKeyPath:@"status"];
    [playerItem removeObserver:self forKeyPath:@"loadedTimeRanges"];
}
/**
 *  通过KVO监控播放器状态
 *
 *  @param keyPath 监控属性
 *  @param object  监视器
 *  @param change  状态改变
 *  @param context 上下文
 */
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
    AVPlayerItem *playerItem=object;
    if ([keyPath isEqualToString:@"status"]) {
        AVPlayerStatus status= [[change objectForKey:@"new"] intValue];
        if(status==AVPlayerStatusReadyToPlay){
//            NSLog(@"正在播放...，视频总长度:%.2f",CMTimeGetSeconds(playerItem.duration));
            [self customVideoSlider:playerItem.duration];//设置播放进度最大值
            int totalTime = (int)CMTimeGetSeconds(playerItem.duration);
            int m = totalTime / 60;
            int s = totalTime % 60;
            NSString *strM = nil;
            NSString *strS = nil;
            if (m < 10) {
                strM = [NSString stringWithFormat:@"0%d", m];
            } else {
                strM = [NSString stringWithFormat:@"%d", m];
            }
            if (s < 10) {
                strS = [NSString stringWithFormat:@"0%d", s];
            } else {
                strS = [NSString stringWithFormat:@"%d", s];
            }
            //设置视频时长的UILabel视图显示值
            self.totalL.text = [NSString stringWithFormat:@"%@:%@", strM, strS];

        }
    }else if([keyPath isEqualToString:@"loadedTimeRanges"]){
        NSArray *array=playerItem.loadedTimeRanges;
//        CMTimeRange totleTimeRange = [array.lastObject CMTimeRangeValue];
//        float totleSeconds = CMTimeGetSeconds(totleTimeRange.duration);
        CMTimeRange timeRange = [array.firstObject CMTimeRangeValue];//本次缓冲时间范围
        
        float startSeconds = CMTimeGetSeconds(timeRange.start);
        float durationSeconds = CMTimeGetSeconds(timeRange.duration);
        NSTimeInterval totalBuffer = startSeconds + durationSeconds;//缓冲总长度
        CGFloat totalTime = CMTimeGetSeconds(playerItem.duration);
        [self.progress setProgress:totalBuffer / totalTime animated:YES];
//        NSLog(@"共缓冲：%.2f",totalBuffer);
        
    }
}

// MV播放界面中间的button
- (void)tempBtnAction
{
    [self.player play];
    self.tempBtn.hidden = YES;
    [self.playBtn setImage:[UIImage imageNamed:@"iconfont-zanting"] forState:UIControlStateNormal];
}

#pragma 点击隐藏控制view
- (void)tapAction:(UITapGestureRecognizer *)tap {
    
    if (self.tempV.hidden == YES) {
        self.tempV.hidden = NO;
    } else {
        self.tempV.hidden = YES;
    }
}

#pragma mark - UI事件
/**
 *  点击播放/暂停按钮
 *
 *  @param sender 播放/暂停按钮
 */
- (void)playAction:(UIButton *)sender
{
    //    AVPlayerItemDidPlayToEndTimeNotification
    //AVPlayerItem *playerItem= self.player.currentItem;
    if(self.player.rate==0){ //说明是暂停
        [sender setImage:[UIImage imageNamed:@"iconfont-zanting"] forState:UIControlStateNormal];
        [self.player play];
        self.tempV.hidden = YES;
        self.tempBtn.hidden = YES;
    }else if(self.player.rate==1){//正在播放
        [self.player pause];
        [sender setImage:[UIImage imageNamed:@"iconfont-iconfontbofang"] forState:UIControlStateNormal];
        self.tempBtn.hidden = NO;
    }
}

// 全屏
- (void)largeAction
{
#pragma 切换VC全屏
//    float current= self.slider.value;
////    NSLog(@"%f", current);
////    self.slider.value
//
//    MVFullViewController *fullVC = [[MVFullViewController alloc] init];
//    fullVC.mvStr = self.mvStr;
//    [fullVC.slider setValue:current animated:YES];
//    [self presentViewController:fullVC animated:YES completion:^{
//        
//        
//    }];
    
    
#pragma 改view坐标全屏
    if (_isRotation) {
        self.isRotation = NO;
        [UIView animateWithDuration:0.2 animations:^{
            
            [self.MvPlayView removeFromSuperview];
            
            self.MvPlayView.transform = CGAffineTransformRotate(self.MvPlayView.transform, -M_PI_2);
            
            [self createMVView:self.originalFrame];
            
            self.MvPlayView.center = CGPointMake(self.originalFrame.origin.x + self.originalFrame.size.width/2.0, self.originalFrame.origin.y + self.originalFrame.size.height/2.0);
            
        }];
        
    } else {
        self.isRotation = YES;
        
        [self.MvPlayView removeFromSuperview];
        
        [UIView animateWithDuration:0.2 animations:^{
       
            CGRect Fullframe = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);

            [self createMVView:Fullframe];
            
            self.MvPlayView.center = CGPointMake([UIScreen mainScreen].bounds.size.width/2.0, ([UIScreen mainScreen].bounds.size.height)/2.0);
            
            self.MvPlayView.transform = CGAffineTransformRotate(self.MvPlayView.transform, M_PI_2);
        }];
        
    }
    
}

// 音量slider

- (void)volumeSet:(UISlider *)slider
{
    NSArray *audioTracks = [self.playerItem.asset tracksWithMediaType:AVMediaTypeAudio];

    NSMutableArray *allAudioParams = [NSMutableArray array];
    for (AVAssetTrack *track in audioTracks) {
        AVMutableAudioMixInputParameters *audioInputParams =
        [AVMutableAudioMixInputParameters audioMixInputParameters];
        [audioInputParams setVolume:slider.value atTime:kCMTimeZero];
        [audioInputParams setTrackID:[track trackID]];
        [allAudioParams addObject:audioInputParams];
    }
    
    AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix];
    [audioMix setInputParameters:allAudioParams];
    
    [_playerItem setAudioMix:audioMix];
}

//UISlider基本设置
- (void)customVideoSlider:(CMTime)duration {
    
    self.slider.maximumValue = CMTimeGetSeconds(duration);
    self.slider.minimumValue = 0.0;
    NSLog(@"%f", self.slider.maximumValue);
}

// slider 拖动视屏跟着动
- (void)sliderAction:(UISlider *)sender
{
    if (self.player.rate == 0) {

        [self.player seekToTime:CMTimeMake((int)sender.value*10, 10.0)];
//        [self.player play];
//        [self.playBtn setImage:[UIImage imageNamed:@"iconfont-zanting"] forState:UIControlStateNormal];
    } else if(self.player.rate == 1) {
        [self.player pause];
        [self.player seekToTime:CMTimeMake((int)sender.value*10, 10.0)];
        [self.player play];
        [self.playBtn setImage:[UIImage imageNamed:@"iconfont-zanting"] forState:UIControlStateNormal];
    }
}

- (void)stop
{
    [self.player pause];
    [self.player.currentItem cancelPendingSeeks];
    [self.player.currentItem.asset cancelLoading];
}

// 分享的代理方法
- (void)shareMV
{
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"569dabd8e0f55a4136000ffe"
                                      shareText:self.mvStr
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToRenren,UMShareToDouban,UMShareToTencent,nil]
                                       delegate:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
